package com.example.llm.learn.api.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResponse<T> {

    private static final String SUCCESS_MSG = "请求成功";

    private Integer code;

    private T data;

    private String message;

    public static <T> CommonResponse<T> ok(T data) {
        CommonResponse<T> commonResponse = ok();
        commonResponse.setData(data);
        return commonResponse;
    }

    public static <T> CommonResponse<T> ok() {
        CommonResponse<T> commonResponse = new CommonResponse<>();
        commonResponse.setCode(200);
        commonResponse.setMessage(SUCCESS_MSG);
        return commonResponse;
    }

    public static <T> CommonResponse<T> error401() {
        return new CommonResponse<>(401,null, "认证失败");
    }

    public static <T> CommonResponse<T> error500() {
        return new CommonResponse<>(500,null, "服务器内部错误");
    }

    public static <T> CommonResponse<T> error500(String message) {
        return new CommonResponse<>(500,null, message);
    }

}